﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace MilkmanProblem
{
    class Program
    {
        public class Cow
        {
            public Int32 weight;
            public Int32 production;

            public Cow(Int32 w, Int32 p)
            {
                this.weight = w;
                this.production = p;
            }
        }

        static void Main(string[] args)
        {
            TextReader consoleReader = Console.In;

            string input = consoleReader.ReadToEnd();
            string[] problems = input.Split('\n');

            foreach (string p in problems)
            {
                string[] values = p.Split(' ');

                Int32 numCows = Int32.Parse(values[0]);
                Int32 maxWeight = Int32.Parse(values[1]);

                string[] weights = values[2].Split(',');
                string[] productions = values[3].Split(',');

                Cow[] cows = new Cow[numCows];
                for (int i = 0; i < weights.Length; i++)
                {
                    cows[i] = new Cow(Int32.Parse(weights[i]), Int32.Parse(productions[i]));
                }

                Console.WriteLine(SolveProblem(cows, maxWeight).ToString());
            }
        }

        private static Int32 SolveProblem(Cow[] cows, Int32 maxWeight)
        {
            Int32[,] matrix = new Int32[cows.Length + 1, maxWeight + 1];

            for (int i = 1; i <= cows.Length; i++)
            {
                for (int w = 0; w <= maxWeight; w++)
                {
                    Cow c = cows[i - 1];
                    if (c.weight <= w)
                    {
                        if (c.production + matrix[i - 1, w - c.weight] > matrix[i - 1, w])
                        {
                            matrix[i, w] = c.production + matrix[i - 1, w - c.weight];
                        }
                        else
                        {
                            matrix[i, w] = matrix[i - 1, w];
                        }
                    }
                    else
                    {
                        matrix[i, w] = matrix[i - 1, w];
                    }
                }
            }

            return matrix[cows.Length, maxWeight];
        }
    }
}
